<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/4 0004
 * Time: 1:59
 */

namespace App\Http\Controllers\Blog;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\Blog\BlogService;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Category\CateController;
//use Illuminate\Support\Facades\Redis;
use Session,Config;
use Cache;

class BlogController extends Controller
{

    private $token;
    private $cate;

    public function __construct(CateController $cate)
    {

        $this->cate = $cate;
    }

    /**
     * @return view
     * 博客列表页面
     */
    public function index()
    {
        $cateinfo = $this->cate->getCateList();
        $keyword = $this->cate->getKeywordListForeach();

        return view('Blog.blog_list')->with('cateinfo',$cateinfo['data'])->with('keyword',$keyword['data']);
    }


    /**
     * @param Request $request
     * @return bool|mixed|string
     * 添加博客
     */
    public function addBlog(Request $request)
    {
        $params = $request->except('_token');
        $params['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Blog = new BlogService();
        $ret =  $Blog->addBlog($params);

        return $ret;

    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 博客列表
     */
    public function getBlogList(Request $request)
    {
        $params = $request->except('_token');
        $params['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Blog = new BlogService();
        $ret =  $Blog->getBlogList($params);
        return $ret;
    }

    public function previewBlog(Request $request){
        $params = $request->except('_token');
        $params['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Blog = new BlogService();
        $ret =  $Blog->previewBlog($params);
        return $ret;

    }


}